#!/usr/bin/env python3
# _*_ coding: utf-8 _*_


from ctypes import *
import platform


if __name__ == '__main__':
	if platform.system() == 'Windows':
		lib_ext = '.dll'
	elif platform.system() == 'Linux':
		lib_ext = '.so'
	elif platform.system() == 'Darwin':
		lib_ext = '.dylib'
	libname = './libdemo_dll' + lib_ext
	library = cdll.LoadLibrary(libname)

	library.pointerTest.argtypes = [POINTER(c_int), POINTER(c_float)]
	library.pointerTest.restype = c_void_p

	int_a = c_int(91)
	float_b = c_float(82.2)
	print("a:", int_a.value)
	print("b:", float_b.value)
	library.pointerTest(byref(int_a), byref(float_b))

	print("out a:", int_a.value)
	print("out b:", float_b.value)

	# 字符指针
	library.mallocTest.argtypes = [c_char_p] # 必须加中括号
	library.mallocTest.restype = c_void_p
	# word = c_char * 32
	word = (c_char * 32)() # 必须用这种
	library.mallocTest(word)
	print("out word:", word.value)
